<template>
  <div>
     <router-link to="/" tag="div" class="header-abs" v-show="showAbs">
       <div class="iconfont icon-detail-back">&#xe624;</div>
     </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="iconfont detail-fixed-back">&#xe624;</div>
      </router-link>
      <div>景点详情</div>
    </div>
  </div>
</template>

<script>
  export default {
    name:'DetailHeader',
    data(){
      return{
       showAbs:true,
       opacityStyle:{
         opacity:0
       }
      }
    },
    mounted(){
      window.addEventListener('scroll',this.handleScroll)
    },
    deactivated(){
      window.removeEventListener('scroll',this.handleScroll)
    },
    methods:{
      handleScroll(){
        const tops = document.documentElement.scrollTop;
        if(tops>60){
          this.showAbs = false;
          let opacity = tops/140;
          opacity = opacity>1 ? 1:opacity;
          this.opacityStyle = {
            opacity
          }
        }else{
          this.showAbs = true;
        }
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-abs{
    position:absolute;
    left:.2rem;
    top:.2rem;
    width:.8rem;
    height:.8rem;
    line-height:.8rem;
    text-align:center;
    border-radius:50%;
    background:rgba(0,0,0,.5);
    .icon-detail-back{
      color:#fff;
      font-size:.4rem;
    }
  }

  .header-fixed{
    height:.86rem;
    line-height:.86rem;
    color:#fff;
    font-size:.32rem;
    background-color:$bgColor;
    text-align:center;
    position:fixed;
    left:0;
    right:0;
    top:0;
    z-index:2;
    .detail-fixed-back{
      width:.64rem;
      text-align:center;
      font-size:.4rem;
      color:#fff;
      position:absolute;
      left:0;
      top:0;
    }
  }
</style>
